let keyAnima = true
let index;
const functionA = function () {
    const getFbt1s = document.getElementsByClassName("fb1");
    getFbt1s[0].classList.add("blueBut");

    for (let index = 0; index < getFbt1s.length; index++) {
        const element = getFbt1s[index];
        element.addEventListener("click", (e) => {
            for (let index = 0; index < getFbt1s.length; index++) {
                const elements = getFbt1s[index];
                if (elements.classList.toString().indexOf("blueBut") != -1) {
                    elements.classList.remove("blueBut");
                    e.target.classList.add("blueBut");
                    return;
                }
            }
        });
    }
};
const cloneCard = function () {
    const topScroll = document.getElementById("topScroll");
    const botScroll = document.getElementById("botScroll");
    const topNode = topScroll.children;
    const botNode = botScroll.children;
    const len = topNode.length ? topNode.length : 5;
    for (let index = 0; index < len; index++) {
        const element = topNode[index];
        const elements = botNode[index];
        topScroll.append(element.cloneNode(true));
        botScroll.append(elements.cloneNode(true));
    }
};


window.onscroll = function () {
    const docHei = document.body.offsetHeight
    // scrollY
    const scrY = window.scrollY;

    const leftNav = document.getElementById("leftNav"); 

    const leftNavHei = leftNav.offsetHeight;
    const headTitHei = document.getElementById("headTit").offsetHeight;
    const hotHei = document.getElementById("hot").offsetHeight;
    const featureHei = document.getElementById("feature").offsetHeight;
    const optionHei = document.getElementById("option").offsetHeight;
    const feedBackHei = document.getElementById("feedBack").offsetHeight;
    const reportHei = document.getElementById("report").offsetHeight;
    const lastNavHei = document.getElementById("lastNav").offsetHeight;
    const whitePaperHei = reportHei / 2;
    const zxHei = reportHei / 2;
    // 进入要消失的位置
    const inOption = headTitHei + hotHei + featureHei + optionHei;

    let base = headTitHei + hotHei - leftNavHei;
    
    
    if (
        scrY < leftNavHei ||
        (scrY > inOption - whitePaperHei &&
            scrY < inOption + feedBackHei - whitePaperHei / 2) ||
        scrY > docHei - lastNavHei - leftNavHei * 2 +80
    ) {
        leftNav.style.visibility = "hidden";
        keyAnima = true;
    } else {
        leftNav.style.visibility = "visible";
        if (keyAnima == true) {
            comAnima(
                leftNav,
                [
                    {
                        opacity: 0,
                    },
                    {
                        opacity: 1,
                    },
                ],
                1000,
                "ease",
                0,
                1,
                "normal"
            );
            keyAnima = false;
        }
    }    
    // setStorage anima
    if (scrY < base) {
        index = 0;
    } else if (scrY < (base += featureHei)) {
        index = 1;
    } else if (scrY < (base += optionHei)) {
        index = 2;
    } else if (scrY < (base += feedBackHei)) {
        index = 3;
    } else if (scrY < (base += whitePaperHei)) {
        index = 4;
    } else if (scrY < (base += zxHei)) {
        index = 5;
    } 


    initLeft(index);
};
window.onload = function () {
    pMove();
    functionA();
    cloneCard();
    addAnime();
    comAnima(element, 2000, 2000, "ease", 2000, Infinity,);
};
